package com.heima.wemedia.controller;

import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.admin.dtos.NewsAuthDto;
import com.heima.model.media.dtos.WmNewsResultDTO;
import com.heima.wemedia.service.WmNewsService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class NewsController {
    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 分页查询自媒体文章
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/news_auth/list")
    public PageResult<WmNewsResultDTO> list(@RequestBody NewsAuthDto dto){
        return wmNewsService.findByPageAndTitle(dto);
    }

    /**
     * 通过id查找自媒体文章
     * @param id
     * @return
     */
    @GetMapping("/api/v1/news_auth/one/{id}")
    public ResponseResult<WmNewsResultDTO> findById(@PathVariable Integer id){
        WmNewsResultDTO wmNewsResultDTO = wmNewsService.findById(id);
        return ResponseResult.ok(wmNewsResultDTO);
    }
    @PostMapping("/api/v1/news_auth/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto dto){
        wmNewsService.authFail(dto);
        return ResponseResult.ok();
    }
    @PostMapping("/api/v1/news_auth/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto dto){
        wmNewsService.authPass(dto);
        return ResponseResult.ok();
    }

}
